/*** vender ***/
package comm;

import db.DataBase;

public class Products {

  private static String[][] data;
  private static String[] headers;

  /** implementar *********************************************************/
  public static String[][] getData() {

    String[][] old = (data == null) ? null : new String[data.length][data[0].length];
    data = DataBase.readData(DataBase.PRODUCTS);


     if(old != null) {
       for(int i = 0; i < data.length; i++)
         for(int j = 0; j < data[0].length; j++)
           old[i][j] = data[i][j];
     }


    for(int i = 0; i < data.length; i++) {
      if(data != null && old != null && i < data.length) {
        data[i][5] = old[i][5];
      } else {
        data[i][5] = "0";
      }
    }

    return data;
  }

  public static String[] getHeaders() {
    return headers = new String[]{
              "ID", "Nome", "Tipo", "Preço", "Estoque Global", "Estoque Local"
            };
  }

  public static String[] getData(int row) {
    return data[row];
  }

  public static String[] getData(String id) {
    for (String[] s : data) {
      if (s[0].equals(id)) {
        return s;
      }
    }
    return null;
  }
}
